<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-tabs class="tab" v-model="activeName">
          <el-tab-pane label="销售额" name="sale"></el-tab-pane>
          <el-tab-pane label="访问量" name="visite"></el-tab-pane>
        </el-tabs>
        <div class="right">
          <span @click="setDay">今日</span>
          <span @click="setWeek">本周</span>
          <span @click="setMonth">本月</span>
          <span @click="setYear">本年</span>
          <el-date-picker
            style="width:300px"
            v-model="date"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </div>
      </div>
      <div>
        <el-row>
          <el-col :span="20">
            <div
              class="charts"
              ref="charts"
              style="width: 100%; height: 300px"
            ></div>
          </el-col>
          <el-col :span="4">
            <div class="">
              <h4>门店{{ title }}排名</h4>
              <ul>
                <li>
                  <span class="rightIndex">1</span>
                  <span>北京店</span>
                  <span>68023</span>
                </li>
                <li>
                  <span class="rightIndex">2</span>
                  <span>上海店</span></span>
                  <span>60000</span>
                </li>
                <li>
                  <span class="rightIndex">3</span>
                  <span>广州店</span>
                  <span>50000</span>
                </li>
                <li>
                  <span class="rightTwo">4</span>
                  <span>深圳店</span>
                  <span>30001</span>
                </li>
                <li>
                  <span class="rightTwo">5</span>
                  <span>苏州店</span>
                  <span>20001</span>
                </li>
                <li>
                  <span class="rightTwo">6</span>
                  <span>武汉店</span>
                  <span>110110</span>
                </li>
                <li>
                  <span class="rightTwo">7</span>
                  <span>杭州店</span>
                  <span>11001</span>
                </li>
              </ul>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script>
import echarts from "echarts";
import dayjs from 'dayjs'
export default {
  data() {
    return {
      activeName: "sale",
      myEcharts: null,
      date: []
    };
  },
  computed: {
    title() {
      return this.activeName == "sale" ? "销售额" : "访问量";
    },
  },
  mounted() {
    this.myEcharts = echarts.init(this.$refs.charts);
    this.myEcharts.setOption({
      title: {
        text: "销售额趋势",
      },
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        left: "3%",
        right: "4%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: [
            "一月",
            "二月",
            "三月",
            "四月",
            "五月",
            "六月",
            "七月",
            "八月",
            "九月",
            "十月",
            "十一月",
            "十二月",
          ],
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          type: "value",
        },
      ],
      series: [
        {
          name: "Direct",
          type: "bar",
          barWidth: "60%",
          data: [70, 52, 200, 334, 390, 330, 220, 110, 80, 98, 30, 100],
          color: "yellowgreen",
        },
      ],
    });
  },
  watch: {
    title() {
      //重新修改图标配置的数据
      this.myEcharts.setOption({
        title: {
          text: this.title + "趋势",
        },
      });
    },
  },
  methods:{
    setDay(){
      const day = dayjs().format('YYYY-MM-DD')
      this.date = [day,day]
    },
    setWeek(){
      const start = dayjs().day(1).format("YYYY-MM-DD")
      const end = dayjs().day(7).format("YYYY-MM-DD")
      this.date = [start,end]
    },
    setMonth(){
      const start  = dayjs().startOf('month').format('YYYY-MM-DD')
      const end = dayjs().endOf("month").format('YYYY-MM-DD')
      this.date  = [start,end]
    },
    setYear(){
       const start  = dayjs().startOf('year').format('YYYY-MM-DD')
      const end = dayjs().endOf("year").format('YYYY-MM-DD')
      this.date  = [start,end]
    }
  }
};
</script>

<style>
.box-card {
  margin: 10px 0;
}
.clearfix {
  display: flex;
  justify-content: space-between;
  position: relative;
}
.tab {
  width: 100%;
}
.right {
  position: absolute;
  right: 0;
}

.right span {
  margin: 0 10px;
}
ul {
  padding: 0;
  list-style: none;
  width: 100%;
  height: 300px;
}
ul li {
  height: 8%;
  margin: 10px 0;
}
ul li span {
  margin-right: 10px;
}
.rightIndex {
  width: 20px;
  height: 20px;
  float: left;
  border-radius: 50%;
  background-color: #ccc;
  color: white;
  text-align: center;
}
.rightTwo {
  width: 20px;
  height: 20px;
  float: left;
  text-align: center;
}

</style>
<style scoped>
::v-deep .el-card__header {
  border-bottom: none;
}
</style>
